/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_SIP_HEADER_H
#define MK_SIP_HEADER_H
#include "MkUtil/MkTypes.h"

class MkApi CMkSipAcceptEncoding
{
public:
    CMkSipAcceptEncoding() {};
    ~CMkSipAcceptEncoding() {};
    Uint32 Parse(const MkString& strEncoding);
    Uint32 ToString(MkString& strEncoding) const;
    const MkString& GetElement() const { return m_Element; }
    const MkMapString& GetParam()const { return m_MapParam; }
    Uint32 GetParamValue(const MkString& strKey, MkString& strValue) const;
    BOOL IsEmpty() const { return m_Element.empty(); }

    void SetElement(const MkString& Element) { m_Element = Element; }
    Uint32 UpdateParam(const MkString& strKey, const MkString& strValue);
protected:
private:
    MkString        m_Element;
    MkMapString    m_MapParam;
};

class MkApi CMkSipContentType
{
public:
    CMkSipContentType() {};
    ~CMkSipContentType() {};
    Uint32 Parse(const MkString& strContentType);
    Uint32 ToString(MkString& strContentType) const;
    const MkString& GetType() const { return m_Type; }
    const MkString& GetSubType()const { return m_SubType; }
    const MkMapString& Param()const { return m_MapParam; }
    Uint32 GetParamValue(const MkString& strKey, MkString& strValue) const;
    BOOL IsEmpty() const { return m_Type.empty(); }

    void SetType(const MkString& strType) { m_Type = strType; }
    void SetSubType(const MkString& SubType) { m_SubType = SubType; }
    Uint32 UpdateParam(const MkString& strKey, const MkString& strValue);
protected:
private:
    MkString                        m_Type;
    MkString                        m_SubType;
    MkMapString                     m_MapParam;
};

class MkApi CMkSipAuthorization
{
public:
    CMkSipAuthorization() {}
    ~CMkSipAuthorization() {}
    Uint32 Parse(const MkString& strAuthorization);
    Uint32 ToString(MkString& strAuthorization) const;
    const MkString& GetAuthType() const { return  m_AuthType; }
    BOOL IsEmpty() const { return m_AuthType.empty(); }

    void SetAuthType(const MkString&  AuthType) { m_AuthType = AuthType; }
    void AddParam(const MkString& strKey, const MkString& strValue);
    Uint32 GetParam(const MkString& strKey, MkString& strValue) const;
protected:
private:
    MkString        m_AuthType;
    MkMapString     m_MapParam;
};

class MkApi CMkSipUri
{
public:
    CMkSipUri();
    ~CMkSipUri() {}
    Uint32 Parse(const MkString& strUri);
    Uint32 ToString(MkString& strUri) const;

    const MkString& GetScheme() const { return m_Scheme; }
    const MkString& GetUserName() const { return m_UserName; }
    const MkString& GetPassword() const { return m_Password; }
    const MkString& GetHost() const { return m_Host; }
    Uint16 GetPort() const { return m_Port; }
    const MkMapString& GetParam()const { return m_MapParam; }
    const MkMapString& GetHeader() const { return m_MapHeader; }
    Uint32 GetParamValue(const MkString& strKey, MkString& strValue) const;
    Uint32 GetHeaderValue(const MkString& strKey, MkString& strValue) const;
    BOOL IsEmpty() const { return m_UserName.empty(); }

    void SetScheme(const MkString& Scheme) { m_Scheme = Scheme; }
    void SetUserName(const MkString& UserName) { m_UserName = UserName; }
    void SetPassword(const MkString& Password) { m_Password = Password; }
    void SetHost(const MkString& Host) { m_Host = Host; }
    void SetPort(Uint16 Port) { m_Port = Port; }

    void UpdateParam(const MkString& strKey, const MkString& strValue);
    void UpdateHeader(const MkString& strKey, const MkString& strValue);
protected:
private:
    MkString                     m_Scheme;  //sip or sips
    MkString                     m_UserName;
    MkString                     m_Password;
    MkString                     m_Host;
    Uint16                       m_Port;
    MkMapString                  m_MapParam;
    MkMapString                  m_MapHeader;
};

class MkApi CMkSipTo
{
public:
    CMkSipTo() {}
    ~CMkSipTo() {}
    Uint32 Parse(const MkString& strTo);
    Uint32 ToString(MkString& strTo) const;
    void SetDesplayName(const MkString& DesplayName) { m_DesplayName = DesplayName; }
    void SetUri(const CMkSipUri& Uri) { m_Uri = Uri; }
    void UpdateParam(const MkString& strKey, const MkString& strValue);

    const MkString& GetDesplayName() const { return m_DesplayName; }
    const CMkSipUri& GetUri()const { return m_Uri; }
    Uint32 GetParamValue(const MkString& strKey, MkString& strValue) const;
    const MkMapString& GetParam() { return m_MapParam; }
    BOOL IsEmpty() const { return m_Uri.IsEmpty(); }
protected:
private:
    MkString                        m_DesplayName;
    CMkSipUri                       m_Uri;
    MkMapString                     m_MapParam;
};

class MkApi CMkSipVia
{
public:
    CMkSipVia();
    ~CMkSipVia() {}
    Uint32 Parse(const MkString& strVia);
    Uint32 ToString(MkString& strVia) const;
    void SetVersion(const MkString& Version) { m_Version = Version; }
    void SetProtocol(const MkString& Protocol) { m_Protocol = Protocol; }
    void SetHost(const MkString& Host) { m_Host = Host; }
    void SetPort(Uint16 Port) { m_Port = Port; }
    void SetComment(const MkString& Comment) { m_Comment = Comment; }
    void UpdateParam(const MkString& strKey, const MkString& strValue);
    void SetBranch(const MkString& Branch) { m_Branch = Branch; }

    const MkString& GetVersion() const { return m_Version; }
    const MkString& GetProtocol()const { return m_Protocol; }
    const MkString& GetHost()const { return m_Host; }
    Uint16 GetPort()const { return m_Port; }
    const MkString& GetComment()const { return m_Comment; }
    const MkMapString& GetParam()const { return m_MapParam; }
    Uint32 GetParamValue(const MkString& strKey, MkString& strValue) const;
    const MkString& GetBranch() const { return m_Branch; }
    BOOL IsEmpty() const { return m_Host.empty(); }
protected:
private:
    Uint32 ParseVersionProtocol(const MkString& Content);
    Uint32 ParseHostPort(const MkString& Content);
    Uint32 ParseComment(const MkString& Content);
private:
    MkString        m_Version;
    MkString        m_Protocol;
    MkString        m_Host;
    Uint16          m_Port;
    MkString        m_Comment;
    MkString        m_Branch;
    MkMapString     m_MapParam;
};

typedef CMkSipContentType                   CMkSipAccept;
typedef CMkSipContentType                   CMkSipAllow;
typedef CMkSipContentType                   CMkSipMimeVersion;
typedef CMkSipAcceptEncoding                CMkSipAcceptLanguage;
typedef CMkSipAcceptEncoding                CMkSipAlertInfo;
typedef CMkSipAcceptEncoding                CMkSipCallInfo;
typedef CMkSipTo                            CMkSipFrom;
typedef CMkSipTo                            CMkSipContact;
typedef CMkSipTo                            CMkSipRecordRoute;
typedef CMkSipTo                            CMkSipRoute;
typedef CMkSipCallInfo                      CMkSipErrorInfo;
typedef CMkSipAuthorization                 CMkSipWwwAuthenticate;
typedef CMkSipAuthorization                 CMkSipAuthenticationInfo;
typedef CMkSipWwwAuthenticate               CMkSipProxyAuthenticate;
typedef CMkSipAuthenticationInfo            CMkSipProxyAuthenticationInfo;
typedef CMkSipAuthorization                 CMkSipProxyAuthorization;
#endif